<#include "/admin/public.html">
<div class="uk-layui-form">
	<form id="myForm" class="layui-form uk-form" action="/admin/informationdisplay/save.html" method="post">
	  <input type="hidden" name="fileurl">
	  <input type="hidden" name="signcode">
	  <div class="layui-form-item form-group">
	    <label class="layui-form-label  control-label">标题</label>
	    <div class="layui-input-inline">
	      <input type="text" name="title" id="title" lay-verify="required"   placeholder="请输入标题" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">示例图</label>
	    <div class="layui-input-inline">
	    	<a class="layui-btn layui-btn-primary" id="informationUploadButton"><i class="layui-icon">&#xe608;</i>新增示例图</a>
	    </div>
	  </div>
	  <div class="layui-form-item layui-hide" id="inforShow">
	    <label class="layui-form-label"></label>
	     <div class="layui-input-inline">
	    	<img id="showInfor" alt="" src=""  style="width:130px" >
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">简介</label>
	    <div class="layui-input-block">
	      <textarea name="briefintroduction" lay-verify="required" placeholder="请输入内容" class="layui-textarea" autocomplete="off"></textarea>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">正文</label>
	    <div class="layui-input-block">
	     <textarea id="content" name="textcontent"  lay-verify="content" placeholder="请输入正文"  style="height: 260px;"></textarea>
	    </div>
	  </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">标签</label>
	    <div class="layui-input-inline">
	     <input type="checkbox" name="signcodeshow" title="热门" value="1">
	    </div>
	  </div>
	  <div class="layui-form-button">
	    <div class="layui-button-block">
	      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
	      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    </div>
	  </div>
	</form>
</div>
 
<script>
var index ,layedit;
var url = "/uploadinformationdisplay";
layui.use(['form', 'layedit'], function(){
  var form = layui.form() ;
  form.verify({ 
      content: function(value, item){ 
      	value = ue.getContent();
	      	if(value.length <= 0) {
	  	      return '请输入正文';
	  	     }
	  	  }
	});   
 //提交
 form.on('submit(formDemo)', function(data){
	 if( !$("input[name=signcodeshow]").prop("checked") ){
		  $("input[name=signcode]").val("0");
	  }else{
		  $("input[name=signcode]").val("1");
	  }
 });
});
UE.Editor.prototype.placeholder = function (justPlainText) {
	var _editor = this;
	_editor.addListener("focus", function () {
		var localHtml = _editor.getPlainTxt();
		if ($.trim(localHtml) === $.trim(justPlainText)) {
			_editor.setContent(" ");
		}
	});
	_editor.addListener("blur", function () {
		var localHtml = _editor.getContent();
		if (!localHtml) {
			_editor.setContent(justPlainText);
		}
	});
	_editor.ready(function () {
		_editor.fireEvent("blur");
	});
};
var ue = UE.getEditor('content', {
	//这里可以选择自己需要的工具按钮名称
	toolbars: [
		['Source','|', 'undo', 'redo', 'removeformat', 'backcolor', 'formatmatch','|', 'italic', 'underline', 'Bold', 'test',
			'forecolor','|', 'justifyleft', 'justifycenter', 'justifyright','|','insertorderedlist' ,'|',
			'fontfamily', 'fontsize','|',
			 'simpleupload','emotion'
		]
	],
	wordCount: false,					//开启字数统计
	elementPathEnabled : false,
	retainOnlyLabelPasted : true
});
//placeholder内容(只能是文本内容)
ue.placeholder("请输入正文");
//上传初始化
var uploader = new plupload.Uploader({
	browse_button: 'informationUploadButton', //触发文件选择对话框的按钮，为那个元素id
	url: "${base}" + url, //服务器端的上传页面地址
	flash_swf_url: '${ctxStatic}/plupload/js//Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
	silverlight_xap_url: '${ctxStatic}/plupload/js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
	filters : {
		mime_types :[ 
			{ title : "Image files", extensions : "jpg,jpeg,png,gif" }, 
		
	 	],
	 	max_file_size : '40mb',
	},
});
 
//在实例对象上调用init()方法进行初始化
uploader.init();
//绑定各种事件，并在事件监听函数中做你想做的事
uploader.bind('FilesAdded',function(uploader, files) {
	$("#inforShow").removeClass("layui-hide");
	$("#showInfor").attr("src","/images/loading-slide.gif");
	uploader.start()
	
})

//上传后回调
uploader.bind('FileUploaded', function(uploader,UploadProgress, responseObject) {
	var obj = $.parseJSON(responseObject.response);
	$("#showInfor").attr("src","/" + obj.filePath);
	$("#showInfor").attr("alt",obj.fileName);
	$("input[name=fileurl]").val(obj.filePath)
});

//报错
uploader.bind('Error',function(up,err) {
	 if(err.code == '-600'){
		 layer.msg('文件最多可上传40M', {icon: 5});
      }	
	
});
</script>